#include <sys/stat.h>
#include <errno.h>

#include <linux/kernel.h>
#include <linux/sched.h>

extern int rw_char(int rw, int dev, char *buf, int count, off_t *pos);

int sys_write(unsigned int fd, char *buf, int count)
{
    struct file *file;
    struct m_inode *inode;

    file = current->filp[fd];
    if (fd >= NR_OPEN || count < 0 || !file)
        return -EINVAL;
    if (!count)
        return 0;
    
    inode = file->f_inode;
    if (S_ISCHR(inode->i_mode))
        return rw_char(WRITE, inode->i_zone[0], buf, count, &file->f_pos);
    
    printk("(Write)inode->i_mode=%06o\n", inode->i_mode);
    return -EINVAL;
}
